import React from 'react';
import {Switch, Route, Redirect} from 'react-router-dom';
import NavBar from '@/components/navbar/NavBar';
import Home from '@/views/index/home/Home';
import PinTuan from '@/views/index/pinTuan/PinTuan';
import ShopCar from '@/views/index/shopCar/ShopCar';
import Logo from '@/assets/logo.png';
import './index.scss';
export default class Index extends React.Component{
    constructor(props){
        super(props);
        this.state = {
            closeAd: false
        }
    }
    componentDidMount () {
        var isClose = localStorage.getItem('closeAd');
        if (isClose === 'true'){
            this.setState({
                closeAd: true
            })
        } else {
            this.setState({
                closeAd: false
            })
        }
    }
    render () {
        var ad =  <div className="ad">
                    <img src={Logo} alt="logo"/>
                    <p>聚美优品，我为自己代言</p>
                    <div className="right">
                        <a href="https://i.jumei.com/m/account/my">前往聚美</a>
                    </div>
                    <i className="iconfont icon-chacha" onClick={this.closeAd.bind(this)}></i>
                </div>
        return (
                <>
                {
                    this.state.closeAd ? '' : ad
                }
                <Switch>
                    <Route path="/home" component={Home}></Route>
                    <Route path="/pinTuan" component={PinTuan}></Route>
                    <Route path="/shopCar" component={ShopCar}></Route>
                    <Redirect to="/home"></Redirect>
                </Switch>
                <NavBar></NavBar>
                </>
        )
    }
    closeAd () {
        var closeAd = localStorage.getItem('closeAd');
        closeAd = 'true';
        localStorage.setItem('closeAd', closeAd);
        this.setState({
            closeAd: true
        })
    }
}
